<script setup>
import {reactive,getCurrentInstance} from "vue";
import {useAllDataStore} from "@/stores"
import {useRouter} from "vue-router"

const loginForm = reactive({
  username: "",
  password: ""
})
const {proxy} = getCurrentInstance()
const store = useAllDataStore()
const router = useRouter()
const handleLogin = async () => {
  const res = await proxy.$api.getMenu(loginForm)
  localStorage.setItem('username', loginForm.username)
  // 使用响应中的菜单列表更新 store 中的菜单列表
store.updataMenuList(res.menuList)
// 将响应中的 token 存储在 store 的状态中
store.state.token = res.token
store.addMenu(router)
// 使用 Vue Router 的 push 方法导航到主页
router.push("/home")



}
</script>

<template>
  <div class="body-login">
    <el-form :model="loginForm" class="login-container" >
      <h1>亮界图书管理系统</h1>
      <h3>请登录</h3>
      <el-form-item>
        <el-input type="input" v-model="loginForm.username" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input type="password" v-model="loginForm.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<style scoped lang="less">
 .body-login{
  width: 100%;
  height: 100%;
  background-image: url("../assets/images/background.jpg");
  background-size: 100%;
  overflow: hidden;
}
.login-container{
  width: 350px;
  background-color: #98fb98;
  border-radius: 15px;
  margin: 250px auto;
  padding: 35px 35px 15PX 35px;
  box-shadow: 0 0 25PX #cacaca;
  border: 1PX solid #eaeaea;
  h1{
    text-align: center;
    margin-bottom: 30px;
    color: #505450;
  }
  h3{
    text-align: center;
    margin-bottom: 30px;
    color: #505450;
  }
  :deep(.el-form-item__content){
    justify-content: center;
  }
}
</style>